/**
 * http://docs.sequelizejs.com/en/latest/docs/scopes/
 */
const Sequelize = require('sequelize');
const databaseDir = require('path').resolve(__dirname, './log.sqlite');

const sequelize = new Sequelize('logserv', 'username', 'password', {
	host: 'localhost',
	dialect: 'sqlite',
	pool: {
		max: 3,
		min: 0,
		idle: 10000
	},
	// SQLite only
	storage: databaseDir
});

const Log = sequelize.define('log', {
	click: Sequelize.STRING,
	page: Sequelize.STRING
}, {
	freezeTableName: true
});

exports.insert = function (data) {
	Log.create(data).then(function (project) {
		console.log('insert', project.dataValues);
	});
};

exports.all = function (callback) {
	Log.findAll().then(function (project) {
		callback(project);
	});
};

exports.Log = Log;